<?php

namespace App\Http\Controllers\Otc;

use App\Http\Controllers\Controller;
use App\Models\Slide;
use App\Models\User;
use Illuminate\Http\Request;

class IndexController extends Controller
{
    /**
     * 法币首页
     * @author hxq
     */
    public function coin_index(Request $request)
    {
        //轮播图
        $slides = Slide::where('del', 1)->orderBy('order', 'asc')->get()->toArray();

        return response()->json(['status' => 1, 'msg' => '成功', 'data' => $slides]);
    }

    /**
     * 用户信息
     * @author hxq
     * @param  Request $request [description]
     * @return [type]           [description]
     */
    public function user_info(Request $request)
    {
        //验证参数
        if (!$request->has('uid')) {
            //缺少参数
            return respF(1003);
        }
        //用户ID
        $uid = $request->get('uid');
        //查找用户
        $user = User::find($uid);
        //用户不存在
        if (!$user) {
            //返回错误
            return respF(1001);
        }
        //null array
        $data = [];
        //user info
        $arr                = [];
        $arr['uid']         = $user->id;
        $arr['account']     = $user->account;
        $arr['nickname']    = $user->nickname;
        $arr['email']       = $user->email;
        $arr['phone']       = $user->phone;
        $arr['headimg']     = config('alioss.host').'/'.$user->headimg;
        $arr['real_status'] = $user->real_status;
        $arr['type']        = $user->type;
        $arr['is_pay_pass'] = $user->pay_pass?1:0;
        //实名认证信息
        $autonym = $user->autonym()->select('name', 'indentity_card', 'back_card', 'front_card', 'status', 'note')->first();
        if ($autonym) {
            $autonym->front_card = config('alioss.host').'/'.$autonym->front_card;
            $autonym->back_card = config('alioss.host').'/'.$autonym->back_card;
            $autonym->hand_card = config('alioss.host').'/'.$autonym->hand_card;
        }
        $data['autonym'] = $autonym;
        //支付信息
        $alipay = $user->user_alipay()->select('alipay_account', 'alipay_code', 'real_name')->first();
        if ($alipay)
            $alipay->alipay_code = config('alioss.host').'/'.$alipay->alipay_code;
        $wechat = $user->user_wechat()->select('wechat_account', 'wechat_code', 'real_name')->first();
        if ($wechat)
            $wechat->wechat_code = config('alioss.host').'/'.$wechat->wechat_code;
        //商家入驻申请
        $enter = null;
        if ($user->enters) {
            $enter['status']   = $user->enters->status;
            $enter['usdt_num'] = $user->enters->usdt_num;
            $enter['note']     = $user->enters->note;
        }
        //商家解绑申请
        $unbind = null;
        if ($user->unbind) {
            $unbind['status'] = $user->unbind->status;
        }

        $data['info']    = $arr;
        $data['autonym'] = $autonym;
        $data['alipay']  = $alipay;
        $data['wechat']  = $wechat;
        $data['enters']  = $enter;
        $data['unbind']  = $unbind;
        $data['token']   = $user->token;

        return response()->json(['status' => 1, 'msg' => '查询成功', 'data' => $data]);
    }
}
